const { src, dest, parallel, series } = require("gulp");
const sass_loader = require("gulp-sass");
const babel = require("gulp-babel");
const swig = require("gulp-swig");
const del = require("del");
const browser = require("browser-sync");
const uglify = require("gulp-uglify");
const css = done => {
  return src("./src/css/**", { base: "src" })
    .pipe(sass_loader())
    .pipe(dest("dist"));
};

const js = () => {
  return src("./src/page/**", { base: "src" })
    .pipe(babel())
    .pipe(uglify())
    .pipe(dest("dist"));
};

const html = () => {
  return src("*html")
    .pipe(swig({ data: { date: new Date().toLocaleDateString() } }))
    .pipe(dest("dist"));
};

const clean = () => {
  return del(["dist/**"]);
};

const server = () => {
  browser.create().init({
    files: "dist/**",
    server: {
      baseDir: "dist"
    }
  });
};

const dev = series(clean, parallel(css, js, html));
module.exports = {
  dev,
  clean,
  server
};
